/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaces;

import Classes.Cliente;
import DAO.ClienteDAO;
import DAO.Conexao;
import controle.ControleCliente;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author 
 */
public class TelaCadastroCliente extends javax.swing.JInternalFrame {
    private JTextField tId;

    /**
     * Creates new form JInternalFrameCadastroCliente
     */
    public TelaCadastroCliente() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tNome = new javax.swing.JTextField();
        tCpf = new javax.swing.JTextField();
        tEmail = new javax.swing.JTextField();
        tUf = new javax.swing.JTextField();
        tCidade = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jblimpar = new javax.swing.JButton();
        jbsalvar = new javax.swing.JButton();
        tTelefone1 = new javax.swing.JTextField();
        tTelefone2 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jbnovo = new javax.swing.JButton();
        jbfechar = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jtbuscaCliente = new javax.swing.JTextField();
        jbBuscaCliente = new javax.swing.JButton();
        jbEditar = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Cadastro de Clientes");
        getContentPane().setLayout(null);

        tNome.setEnabled(false);
        getContentPane().add(tNome);
        tNome.setBounds(90, 150, 380, 30);

        tCpf.setEnabled(false);
        getContentPane().add(tCpf);
        tCpf.setBounds(90, 190, 340, 30);

        tEmail.setEnabled(false);
        getContentPane().add(tEmail);
        tEmail.setBounds(90, 240, 310, 30);

        tUf.setEnabled(false);
        getContentPane().add(tUf);
        tUf.setBounds(90, 310, 60, 30);

        tCidade.setEnabled(false);
        tCidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tCidadeActionPerformed(evt);
            }
        });
        getContentPane().add(tCidade);
        tCidade.setBounds(260, 310, 250, 30);

        jLabel1.setText("Nome :");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(20, 150, 60, 30);

        jLabel2.setText("CPF :");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(20, 200, 50, 20);

        jLabel3.setText("E-mail :");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(20, 240, 50, 30);

        jLabel4.setText("UF : ");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(30, 310, 50, 30);

        jLabel5.setText("Cidade :");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(180, 310, 80, 30);

        jblimpar.setText("Limpar");
        jblimpar.setEnabled(false);
        jblimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jblimparActionPerformed(evt);
            }
        });
        getContentPane().add(jblimpar);
        jblimpar.setBounds(460, 380, 90, 40);

        jbsalvar.setText("Salvar");
        jbsalvar.setEnabled(false);
        jbsalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbsalvarActionPerformed(evt);
            }
        });
        getContentPane().add(jbsalvar);
        jbsalvar.setBounds(190, 380, 90, 40);

        tTelefone1.setEnabled(false);
        getContentPane().add(tTelefone1);
        tTelefone1.setBounds(630, 190, 150, 30);

        tTelefone2.setEnabled(false);
        getContentPane().add(tTelefone2);
        tTelefone2.setBounds(630, 240, 150, 30);

        jLabel6.setText("Telefone 1 :");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(520, 190, 110, 30);

        jLabel7.setText("Telefone 2 :");
        getContentPane().add(jLabel7);
        jLabel7.setBounds(520, 240, 100, 30);

        jbnovo.setText("Novo");
        jbnovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbnovoActionPerformed(evt);
            }
        });
        getContentPane().add(jbnovo);
        jbnovo.setBounds(60, 380, 90, 40);

        jbfechar.setText("Fechar");
        jbfechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbfecharActionPerformed(evt);
            }
        });
        getContentPane().add(jbfechar);
        jbfechar.setBounds(590, 380, 80, 40);

        jLabel8.setText("ID :");
        jLabel8.setToolTipText("Digite o CPF do cliente para buscá-lo");
        getContentPane().add(jLabel8);
        jLabel8.setBounds(20, 90, 50, 30);
        jLabel8.getAccessibleContext().setAccessibleDescription("");

        jtbuscaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtbuscaClienteActionPerformed(evt);
            }
        });
        getContentPane().add(jtbuscaCliente);
        jtbuscaCliente.setBounds(80, 90, 210, 30);

        jbBuscaCliente.setText("Selecionar");
        jbBuscaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBuscaClienteActionPerformed(evt);
            }
        });
        getContentPane().add(jbBuscaCliente);
        jbBuscaCliente.setBounds(350, 80, 110, 40);

        jbEditar.setText("Editar");
        getContentPane().add(jbEditar);
        jbEditar.setBounds(320, 380, 100, 40);

        setBounds(0, 0, 836, 488);
    }// </editor-fold>//GEN-END:initComponents

    private void tCidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tCidadeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tCidadeActionPerformed

    private void jbnovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbnovoActionPerformed
          Novo();        
    }//GEN-LAST:event_jbnovoActionPerformed

    private void jblimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jblimparActionPerformed
        // TODO add your handling code here:
        tNome.setText(" ");
        tCpf.setText(" ");
        tEmail.setText("");
        tTelefone1.setText("");
        tTelefone2.setText("");
        tUf.setText("");
        tCidade.setText("");
    }//GEN-LAST:event_jblimparActionPerformed

    private void jbfecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbfecharActionPerformed
        
        //System.exit(0);
        this.dispose();
    }//GEN-LAST:event_jbfecharActionPerformed

    private void jbsalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbsalvarActionPerformed
       
        try {
            ControleCliente controleCliente = new ControleCliente();
            controleCliente.adiciona(this);
            LimparCampos();
        }  catch (Exception ex) {
            Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
        }    
        
       
    }//GEN-LAST:event_jbsalvarActionPerformed

    private void jtbuscaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtbuscaClienteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtbuscaClienteActionPerformed

    private void jbBuscaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBuscaClienteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jbBuscaClienteActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JButton jbBuscaCliente;
    private javax.swing.JButton jbEditar;
    private javax.swing.JButton jbfechar;
    private javax.swing.JButton jblimpar;
    private javax.swing.JButton jbnovo;
    private javax.swing.JButton jbsalvar;
    private javax.swing.JTextField jtbuscaCliente;
    private javax.swing.JTextField tCidade;
    private javax.swing.JTextField tCpf;
    private javax.swing.JTextField tEmail;
    private javax.swing.JTextField tNome;
    private javax.swing.JTextField tTelefone1;
    private javax.swing.JTextField tTelefone2;
    private javax.swing.JTextField tUf;
    // End of variables declaration//GEN-END:variables
      
    public void Novo(){
        tNome.setEnabled(true);
        tCpf.setEnabled(true);
        tEmail.setEnabled(true);
        tTelefone1.setEnabled(true);
        tTelefone2.setEnabled(true);
        tCidade.setEnabled(true);
        tUf.setEnabled(true);
        jbsalvar.setEnabled(true);
        jblimpar.setEnabled(true);
        jbnovo.setEnabled(false);
        jbBuscaCliente.setEnabled(false);
        jtbuscaCliente.setEnabled(false);
    }
    
    private void LimparCampos() {
        //this.tCodigo.setText(null);
        this.tNome.setText(null);
        this.tCpf.setText(null);
        this.tEmail.setText(null);
        this.tCidade.setText(null);
        this.tUf.setText(null);
        this.tTelefone1.setText(null);
        this.tTelefone2.setText(null);
    }

   public javax.swing.JTextField gettNome(){
       return tNome;
   }
   
   public void settNome(javax.swing.JTextField tNome){
       this.tNome = tNome;
   }
   
   public javax.swing.JTextField gettCpf(){
       return tCpf;
   }
   
   public void settCpf(javax.swing.JTextField tCpf){
       this.tCpf = tCpf;
   }
   
   public JTextField gettEmail(){
       return tEmail;
   }
   public void settEmail(JTextField tEmail){
       this.tEmail= tEmail;
   }
   
   public JTextField gettCidade(){
       return tCidade;
   }
   public void settCidade(JTextField tCidade){
       this.tCidade = tCidade;
   }
   
   public JTextField gettUf(){
       return tUf;
   }
   public void settUf(JTextField tUf){
       this.tUf = tUf;
   }
   
   public JTextField gettTelefone1(){
       return tTelefone1;
   }
   public void settTelefone1(JTextField tTelefone1){
       this.tTelefone1 = tTelefone1;
   }
   
    public JTextField gettTelefone2(){
       return tTelefone2;
   }
   public void settTelefone2(JTextField tTelefone2){
       this.tTelefone2 = tTelefone2;
   }
   
   public JTextField gettId(){
       return tId;
   }
   public void settId(JTextField tId){
       this.tId = tId;
   }
   
   
   

}
